from celery.result import AsyncResult

from app_function.my_apps.projects.tests import router, namespace
from celery_related.common_tasks.tasks import add
from celery_related.celery_app import celery_app


@router.get("/test/", tags=namespace, name="test")
def testtt():
    result = add.delay(1, 2)
    return {"task_id": result.id, "status": result.status}


@router.get("/get_result/", tags=namespace, name="get_result")
async def get_status(task_id: str):
    """查询任务状态和结果"""
    res = AsyncResult(task_id, app=celery_app)
    return {"task_id": task_id, "status": res.status, "result": res.result}
# 0e4de898-bacc-460a-b486-f277658ff5b0